var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        strShow: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        districtVal: [],
        streetShow: !1,
        addressShow: !1,
        addressName: "",
        provice: "",
        configInfo: {},
        apply: {
            realname: "",
            mobile: "",
            company_name: "",
            province_id: "",
            city_id: "",
            district_id: "",
            company_address: "",
            remark: "",
            address: "",
            street_id: ""
        },
        showSex: !1,
        showProtocol: !1,
        FrontIDcard: [],
        backIDcard: [],
        businessFlie: [],
        GenerateFlie: [],
        otherFlie: [],
        sexId: 0,
        checked: !1
    },
    onLoad: function(t) {
        this.getData();
    },
    getData: function() {
        var t = this, e = a.getNetAddresss("plugin.ad-serving.frontend.advertisers.apply.index");
        a._postNetWork({
            url: e,
            data: {},
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    configInfo: e.data
                }), 1 == e.data.status && t._initAddressInfo()) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    submitApply: function() {
        var t = this;
        if (a._isTextEmpty(this.data.apply.realname)) wx.showToast({
            title: "请填写姓名！",
            icon: "none",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.mobile)) wx.showToast({
            title: "请填写联系方式！",
            icon: "none",
            duration: 1500
        }); else if (a._isMoblie(this.data.apply.mobile)) wx.showToast({
            icon: "none",
            title: "请输入正确的手机号",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.province_id) || a._isTextEmpty(this.data.apply.city_id) || a._isTextEmpty(this.data.apply.district_id)) wx.showToast({
            icon: "none",
            title: "请选择省市区",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.street_id)) wx.showToast({
            icon: "none",
            title: "请在后台系统-交易设置-开启街道地址",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.FrontIDcard) || a._isTextEmpty(this.data.backIDcard)) wx.showToast({
            icon: "none",
            title: "请上传身份证正反照！",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.businessFlie)) wx.showToast({
            icon: "none",
            title: "请上传经营许可证！",
            duration: 1500
        }); else if (this.data.checked) {
            var e, s = {
                username: this.data.apply.realname,
                mobile: this.data.apply.mobile,
                sex: this.data.sexId,
                province_id: this.data.apply.province_id,
                city_id: this.data.apply.city_id,
                district_id: this.data.apply.district_id,
                street_id: this.data.apply.street_id,
                address: this.data.apply.address,
                id_card_front: this.data.FrontIDcard[0],
                id_card_side: this.data.backIDcard[0],
                business_certificate: this.data.businessFlie[0],
                production_licence: this.data.GenerateFlie[0],
                other_certificates: this.data.otherFlie
            };
            e = a.getNetAddresss("plugin.ad-serving.frontend.advertisers.apply.apply"), a._postNetWork({
                url: e,
                showToastIn: !1,
                data: s,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? (wx.showToast({
                        title: e.msg,
                        icon: "none",
                        duration: 1500
                    }), t.getData()) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        } else wx.showToast({
            icon: "none",
            title: "请勾选申请协议！",
            duration: 1500
        });
    },
    realnameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.realname": a
        });
    },
    mobileinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.mobile": a
        });
    },
    updateFrontIDcard: function(t) {
        this.setData({
            FrontIDcard: t.detail
        });
    },
    updatebackIDcard: function(t) {
        this.setData({
            backIDcard: t.detail
        });
    },
    updatebusinessFlie: function(t) {
        this.setData({
            businessFlie: t.detail
        });
    },
    updateGenerateFlie: function(t) {
        this.setData({
            GenerateFlie: t.detail
        });
    },
    updateotherFlie: function(t) {
        this.setData({
            otherFlie: t.detail
        });
    },
    showProtocols: function() {
        this.setData({
            showProtocol: !0
        });
    },
    showSexs: function() {
        this.setData({
            showSex: !0
        });
    },
    onCloseSex: function() {
        this.setData({
            showSex: !1
        });
    },
    onCloseProtocol: function() {
        this.setData({
            showProtocol: !1
        });
    },
    onChangechecked: function(t) {
        this.setData({
            checked: t.detail
        });
    },
    selcetSex: function(t) {
        var a = t.currentTarget.dataset.tag;
        this.setData({
            sexId: a,
            "apply.gender": 1 == a ? "男" : "女",
            showSex: !1
        });
    },
    addressShowbtn: function() {
        this.setData({
            addressShow: !0
        });
    },
    showAddBtn: function(a) {
        var e = a.currentTarget.dataset.idex;
        this.setData(t({}, "diydata[" + e + "].showAdd", !0));
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    _initAddressInfo: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("地址信息准备就绪"), t._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), a._getNetWork({
                    url: a.getNetAddresss("member.member-address.address"),
                    success: function(a) {
                        var e = a.data, s = e.data.province, i = e.data.city, o = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: i
                        }), wx.setStorage({
                            key: "districtData",
                            data: o
                        }), t._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    provinceData: a.data
                }), t.setData({
                    "selectAddressData[0].name": a.data[t.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": a.data[t.data.pickerValue[0]].id,
                    "selectAddressData[0].index": t.data.pickerValue[0]
                }), t._getCityData();
            }
        });
    },
    _getCityData: function() {
        var t = this.data.selectAddressData[0];
        console.log("城市", "_data", t);
        var a = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("城市数据筛选", s), a.setData({
                    cityData: s
                }), a.setData({
                    "selectAddressData[1].name": s[a.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[a.data.pickerValue[1]].id,
                    "selectAddressData[1].index": a.data.pickerValue[1]
                }), a._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var t = this.data.selectAddressData[1];
        console.log("地区", "_data", t), console.log(t);
        var a = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("地区数据筛选", s), a.setData({
                    districtData: s
                }), console.log("districtData", s), a.setData({
                    "selectAddressData[2].name": s[a.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[a.data.pickerValue[2]].id,
                    "selectAddressData[2].index": a.data.pickerValue[2]
                }), console.log("over", a.data.selectAddressData);
            }
        });
    },
    bindChange: function(t) {
        var a = t.detail.value;
        this.data.pickerValue[0] != a[0] && (a[1] = 0, a[2] = 0), this.data.pickerValue[1] != a[1] && (a[2] = 0), 
        this.setData({
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        }), this._initAddressInfo();
    },
    resultAdd: function() {
        var t = this.data.selectAddressData, a = t[0].name + " " + t[1].name + " " + t[2].name;
        this.setData({
            addressName: a,
            provice: t[0].name,
            city: t[1].name,
            district: t[2].name
        }), this.setData({
            "apply.province_id": t[0].id,
            "apply.city_id": t[1].id,
            "apply.district_id": t[2].id,
            addressShow: !1
        }), this.getStreet(t[2].id);
    },
    getStreet: function(t) {
        var e = this, s = "";
        s += a.getNetAddresss("member.memberAddress.street"), s += "&district_id=" + t, 
        a._getNetWork({
            url: s,
            success: function(t) {
                var s = t.data;
                1 == s.result && !a._isTextEmpty(s.data) && s.data.length > 0 ? e.setData({
                    districtVal: s.data,
                    strShow: !0
                }) : e.setData({
                    strShow: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    streetShowbtn: function() {
        this.setData({
            streetShow: !0
        });
    },
    treetShowLeft: function() {
        this.setData({
            streetShow: !1
        });
    },
    streetConfirm: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            street: a.areaname,
            "apply.street_id": a.id,
            streetShow: !1
        });
    },
    addressinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.address": a
        });
    },
    gotoHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});